import FlowAssignee from '@/components/Flow/Task/Assignee';
import FlowUsers from '@/components/Flow/Task/User';
import FlowRole from '@/components/Flow/Task/Role';
import FlowDept from '@/components/Flow/Task/Dept';
import FlowPost from '@/components/Flow/Task/Post';

/**
 * 保存选择审批数据
 * @param currentType 组件类型
 * @param nodeId 节点ID
 * @param selectDataList 数据
 * @returns {*[]}
 */
export function assignSelect(currentType, nodeId, selectDataList) {
    const mapItem = (item, idKey, nameKey) => ({id: item[idKey], name: item[nameKey], nodeId: nodeId});
    let selectAssignList = [];

    if ("role" === currentType) {
        selectAssignList = selectDataList.map(item => mapItem(item, 'roleId', 'roleName'));
    } else if ("dept" === currentType) {
        selectAssignList = selectDataList.map(item => mapItem(item, 'id', 'label'));
    } else if ("post" === currentType) {
        selectAssignList = selectDataList.map(item => mapItem(item, 'postId', 'postName'));
    } else if ("assignee" === currentType || "users" === currentType) {
        selectAssignList = selectDataList.map(item => mapItem(item, 'userId', 'nickName'));
    }

    return selectAssignList;
}

/**
 * 任务流转时加载不同的审批类型组件
 * @param assignType 审批类型
 * @param currentComponent 组件
 */
export function setAssignComponentValue(assignType, currentComponent) {
    switch (assignType) {
        case 'assignee':
            currentComponent.value = FlowAssignee;
            break;
        case 'users':
            currentComponent.value = FlowUsers;
            break;
        case 'role':
            currentComponent.value = FlowRole;
            break;
        case 'dept':
            currentComponent.value = FlowDept;
            break;
        case 'post':
            currentComponent.value = FlowPost;
            break;
        default:
            currentComponent.value = null;
    }
}

